package com.sample.ch5filterAndListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
// WebListener 没有设置初始化参数要在web.xml中设置
@WebListener
public class CustomServletContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext context = sce.getServletContext();
        // 获取初始化参数
        String avatars = context.getInitParameter("AVATAR");
        context.setAttribute("avatars",avatars);
        System.out.println("CustomServletContextListener contextInitialized 执行了...");
        System.out.println(context.getAttribute("avatars"));
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    }
}
